package com.kmproject.haifu.mvp.ui.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.widget.alertview.AlertView;
import com.jess.arms.widget.alertview.AlertViewOnItemClickListener;
import com.kmproject.haifu.R;
import com.kmproject.haifu.app.utils.AppUtil;
import com.kmproject.haifu.di.component.DaggerMemberUpdatelevelPaymentComponent;
import com.kmproject.haifu.mvp.contract.MemberUpdatelevelPaymentContract;
import com.kmproject.haifu.mvp.model.entity.beans.ExchangeRateBean;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.MemberCenterUserInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.MemberFeatureBean;
import com.kmproject.haifu.mvp.model.entity.beans.MemberPayResultBean;
import com.kmproject.haifu.mvp.model.entity.resbean.HFLocationBean;
import com.kmproject.haifu.mvp.presenter.MemberUpdatelevelPaymentPresenter;
import com.kmproject.haifu.mvp.ui.activity.MemberCenterMainActivity;
import com.kmproject.haifu.mvp.ui.activity.MemberCenterUpdateLevelActivity;
import com.kmproject.haifu.mvp.ui.adapter.MemberUpdateLevelFeatureAdapter;
import com.kmproject.haifu.mvp.ui.adapter.MemberUpdateLevelRuleAdapter;
import com.library.flowlayout.SpaceItemDecoration;
import com.tencent.mm.sdk.modelbase.BaseResp;

import org.simple.eventbus.Subscriber;
import org.simple.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 07/20/2019 13:40
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class MemberUpdatelevelPaymentFragment extends BaseFragment<MemberUpdatelevelPaymentPresenter> implements MemberUpdatelevelPaymentContract.View {

    //    @BindView(R.id.MemberUpdatelevelPaymentFragment_RecyclerView1)
    RecyclerView MemberUpdatelevelPaymentFragmentRecyclerView1;
    //    @BindView(R.id.MemberUpdatelevelPaymentFragment_zdxf_checkbox)
    CheckBox MemberUpdatelevelPaymentFragmentZdxfCheckbox;
    //    @BindView(R.id.MemberUpdatelevelPaymentFragment_zdxf_txt)
    TextView MemberUpdatelevelPaymentFragmentZdxfTxt;

    LinearLayout MemberUpdatelevelPaymentFragmentKtsjLay;
    @BindView(R.id.MemberUpdatelevelPaymentFragment_RecyclerView2)
    RecyclerView MemberUpdatelevelPaymentFragmentRecyclerView2;
    @BindView(R.id.MemberUpdatelevelPaymentFragment_hytq_lay)
    LinearLayout MemberUpdatelevelPaymentFragmentHytqLay;
    @BindView(R.id.MemberUpdatelevelPaymentFragment_money_txt)
    TextView MemberUpdatelevelPaymentFragmentMoneyTxt;
    @BindView(R.id.MemberUpdatelevelPaymentFragment_sure_txt)
    TextView MemberUpdatelevelPaymentFragmentSureTxt;
    @BindView(R.id.MemberUpdatelevelPaymentFragment_bottom_lay)
    LinearLayout MemberUpdatelevelPaymentFragmentBottomLay;
    Unbinder unbinder;
    MemberUpdateLevelRuleAdapter memberUpdateLevelRuleAdapter;
    MemberUpdateLevelFeatureAdapter memberUpdateLevelFeatureAdapter;
    //    @BindView(R.id.MemberUpdatelevelPaymentFragment_ts_txt)
    TextView MemberUpdatelevelPaymentFragmentTsTxt;
    //    @BindView(R.id.MemberUpdatelevelPaymentFragment_ts_lay)
    LinearLayout MemberUpdatelevelPaymentFragmentTsLay;
    private int selectRuleIndex = 0;
    private MemberCenterUserInfoBean.MemberLevelBean mmemberLevelBean;
    private MemberCenterUserInfoBean memberCenterUserInfoBean;
    private Map<Boolean, List<MemberCenterUserInfoBean.MemberLevelBean>> UpgradeRules = new HashMap<>();
    private List<HousePayWayBean> mhousePayWayBeans;
    private List<MemberFeatureBean> mmemberFeatureBeans;
     List<MemberFeatureBean> memberFeatureBeansForNow;//当前自己会员等级的特权
    public static MemberUpdatelevelPaymentFragment newInstance(int inedx, MemberCenterUserInfoBean.MemberLevelBean memberLevelBean) {
        MemberUpdatelevelPaymentFragment fragment = new MemberUpdatelevelPaymentFragment();
        Bundle args = new Bundle();
        args.putInt("index", inedx);
        args.putSerializable("MemberLevelBean", memberLevelBean);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerMemberUpdatelevelPaymentComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_member_updatelevel_payment, container, false);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        memberCenterUserInfoBean = ((MemberCenterUpdateLevelActivity) getActivity()).getMemberCenterUserInfoBean();
        mmemberLevelBean = (MemberCenterUserInfoBean.MemberLevelBean) getArguments().getSerializable("MemberLevelBean");
        View headView = LayoutInflater.from(getActivity()).inflate(R.layout.updatelevel_payment_header, null);
        MemberUpdatelevelPaymentFragmentKtsjLay = headView.findViewById(R.id.MemberUpdatelevelPaymentFragment_ktsj_lay);
        MemberUpdatelevelPaymentFragmentTsLay = headView.findViewById(R.id.MemberUpdatelevelPaymentFragment_ts_lay);
        MemberUpdatelevelPaymentFragmentTsTxt = headView.findViewById(R.id.MemberUpdatelevelPaymentFragment_ts_txt);
        MemberUpdatelevelPaymentFragmentRecyclerView1 = headView.findViewById(R.id.MemberUpdatelevelPaymentFragment_RecyclerView1);
        MemberUpdatelevelPaymentFragmentZdxfCheckbox = headView.findViewById(R.id.MemberUpdatelevelPaymentFragment_zdxf_checkbox);
        MemberUpdatelevelPaymentFragmentZdxfTxt = headView.findViewById(R.id.MemberUpdatelevelPaymentFragment_zdxf_txt);
        memberUpdateLevelFeatureAdapter = new MemberUpdateLevelFeatureAdapter(new ArrayList<>());
        MemberUpdatelevelPaymentFragmentRecyclerView2.setLayoutManager(new LinearLayoutManager(getActivity()));
        MemberUpdatelevelPaymentFragmentRecyclerView2.setAdapter(memberUpdateLevelFeatureAdapter);
        memberUpdateLevelFeatureAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_RIGHT);
        memberUpdateLevelFeatureAdapter.setHeaderView(headView);
        memberUpdateLevelFeatureAdapter.setFooterView(LayoutInflater.from(getActivity()).inflate(R.layout.v_divider_12_line, null));

        //调整RecyclerView的排列方向
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        MemberUpdatelevelPaymentFragmentRecyclerView1.setLayoutManager(layoutManager);
        MemberUpdatelevelPaymentFragmentRecyclerView1.addItemDecoration(new SpaceItemDecoration(AppUtil.dp2px(5)));

        memberUpdateLevelRuleAdapter = new MemberUpdateLevelRuleAdapter(new ArrayList<>(), new MemberUpdateLevelRuleAdapter.ItemClickCallback() {
            @Override
            public void callback(int index) {
                selectRuleIndex = index;
                MemberUpdatelevelPaymentFragmentMoneyTxt.setText(AppUtil.moneyForat(String.valueOf(memberUpdateLevelRuleAdapter.getData().get(index).getDiscountAmount())) + "P");
//                MemberUpdatelevelPaymentFragmentZdxfTxt
//                setConfireBtn();
                if ((mmemberLevelBean.getListOrder() < memberCenterUserInfoBean.getMemberLevel().getListOrder())) {
                    //getIsAutoRenew 等于1 表示已经连续续费
                    MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.GONE);
                } else {
                    MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.VISIBLE);
                    if (mmemberLevelBean.getListOrder() == memberCenterUserInfoBean.getMemberLevel().getListOrder()) {
                        //当前的和默认选中的会员级别和用户的级别相同
                        tsShowContrl_new(memberCenterUserInfoBean, memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex));
                    } else {
                        //当前会员等级和用户的等级不一样，就默认都不选中自动续费
                        //请求到期提示数据
                        if (mmemberLevelBean.getListOrder() > memberCenterUserInfoBean.getMemberLevel().getListOrder()) {
                            //请求到期提示数据
                            tsShowContrl_new(memberCenterUserInfoBean, memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex));
                        } else {
                            MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.GONE);
                        }
                    }
                }
                if (!MemberUpdatelevelPaymentFragmentZdxfCheckbox.isChecked()) {
                    MemberUpdatelevelPaymentFragmentZdxfTxt.setText("到期前1天自动续费" + memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex).getMonthAmount() + "P/月，可随时取消");
                } else {
                    MemberUpdatelevelPaymentFragmentZdxfTxt.setText("到期前1天自动续费" + memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex).getDiscountAmount() + "P，可随时取消");
                }
            }
        });
        MemberUpdatelevelPaymentFragmentRecyclerView1.setAdapter(memberUpdateLevelRuleAdapter);
        mPresenter.getMemberFunctionConfigure(mmemberLevelBean.getMemberLevelId(), mmemberFeatureBeans);//获取这个会员等级的特权，
        if (memberCenterUserInfoBean.getMemberLevel().getLevelType()!=0)
        {
            //非普通会员的时候
            mPresenter.getMemberFunctionConfigureForNow(memberCenterUserInfoBean.getMemberLevel().getMemberLevelId());//获取当前自己所属等级的特权，获取汇率的时候使用
        }
        if (mmemberLevelBean.getListOrder() == memberCenterUserInfoBean.getMemberLevel().getListOrder()) {
            //当前的和默认选中的会员级别和用户的级别相同
            if (memberCenterUserInfoBean.getMemberLevel().getIsAutoRenew() == 1) {
                //getIsAutoRenew 等于1 表示已经连续续费
                MemberUpdatelevelPaymentFragmentZdxfCheckbox.setChecked(true);
                MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.GONE);
            } else {

                MemberUpdatelevelPaymentFragmentZdxfCheckbox.setChecked(false);
                MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.VISIBLE);
            }

        } else if (mmemberLevelBean.getListOrder() > memberCenterUserInfoBean.getMemberLevel().getListOrder()) {
            //当前会员等级和用户的等级不一样，就默认都不选中自动续费
            MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.VISIBLE);
            MemberUpdatelevelPaymentFragmentZdxfCheckbox.setChecked(false);
            //请求到期提示数据

        } else {
            //低于当前等级的就隐藏提示
            MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.GONE);
        }

        //自动续费相关操作
//        MemberUpdatelevelPaymentFragmentZdxfCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//
//
//                if (isChecked||(mmemberLevelBean.getListOrder() <memberCenterUserInfoBean.getMemberLevel().getListOrder())) {
//                    //getIsAutoRenew 等于1 表示已经连续续费
//                    MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.GONE);
//                } else {
//                    MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.VISIBLE);
//                    if (mmemberLevelBean.getListOrder() == memberCenterUserInfoBean.getMemberLevel().getListOrder()) {
//                        //当前的和默认选中的会员级别和用户的级别相同
//                        MemberUpdatelevelPaymentFragmentTsTxt.setText("您的"+memberCenterUserInfoBean.getMemberLevel().getLevelName()+"于"+memberCenterUserInfoBean.getMemberLevel().getExpiresTime()+"日到期，购买后有效期将顺延");
//                    } else {
//                        //当前会员等级和用户的等级不一样，就默认都不选中自动续费
//                        //请求到期提示数据
//                        if (mmemberLevelBean.getListOrder()> memberCenterUserInfoBean.getMemberLevel().getListOrder()){
//                            //请求到期提示数据
//                            MemberUpdatelevelPaymentFragmentTsTxt.setText("您的"+memberCenterUserInfoBean.getMemberLevel().getLevelName()+"还有"+memberCenterUserInfoBean.getResidualTimeDay()+"天到期，如需升级到"+mmemberLevelBean.getLevelName()+"将为您自动\n兑换成"+((int)(memberCenterUserInfoBean.getResidualAmount()/memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex).getDayAmount()))+"天"+mmemberLevelBean.getLevelName()+"，即购买后有效期将顺延"+((int)(memberCenterUserInfoBean.getResidualAmount()/memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex).getDayAmount()))+"天。");
//                        }else {
//                            MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.GONE);
//                        }
//                    }
//                }
//
//
//
//                if (UpgradeRules.containsKey(isChecked)) {
//                    memberUpdateLevelRuleAdapter.setAutoRenew(isChecked);
//                    memberUpdateLevelRuleAdapter.setNewData(UpgradeRules.get(isChecked));
//                    if (!MemberUpdatelevelPaymentFragmentZdxfCheckbox.isChecked())
//                    {
//                        MemberUpdatelevelPaymentFragmentZdxfTxt.setText("到期前1天自动续费"+memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex).getMonthAmount()+"P/月，可随时取消");
//                    }else {
//                        MemberUpdatelevelPaymentFragmentZdxfTxt.setText("到期前1天自动续费"+memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex)+"P，可随时取消");
//                    }
//                    return;
//                }
//                mPresenter.getMemberUpgradeRuleList(mmemberLevelBean.getMemberLevelId(), isChecked ? "1" : "0");
//            }
//        });
        setConfireBtn();
        mPresenter.dictList(mhousePayWayBeans);
        if (mmemberLevelBean.getLevelType() == 0) {
            //普通会员
            MemberUpdatelevelPaymentFragmentKtsjLay.setVisibility(View.GONE);
            MemberUpdatelevelPaymentFragmentBottomLay.setVisibility(View.GONE);
        } else {
            //非普通会员获取升级规则
            mPresenter.getMemberUpgradeRuleList(mmemberLevelBean.getMemberLevelId(), "0", UpgradeRules.containsKey(false) ? UpgradeRules.get(false) : null);
        }
//        tsShowContrl_new(null, null);
    }


    /**
     * 通过此方法可以使 Fragment 能够与外界做一些交互和通信, 比如说外部的 Activity 想让自己持有的某个 Fragment 对象执行一些方法,
     * 建议在有多个需要与外界交互的方法时, 统一传 {@link Message}, 通过 what 字段来区分不同的方法, 在 {@link #setData(Object)}
     * 方法中就可以 {@code switch} 做不同的操作, 这样就可以用统一的入口方法做多个不同的操作, 可以起到分发的作用
     * <p>
     * 调用此方法时请注意调用时 Fragment 的生命周期, 如果调用 {@link #setData(Object)} 方法时 {@link Fragment#onCreate(Bundle)} 还没执行
     * 但在 {@link #setData(Object)} 里却调用了 Presenter 的方法, 是会报空的, 因为 Dagger 注入是在 {@link Fragment#onCreate(Bundle)} 方法中执行的
     * 然后才创建的 Presenter, 如果要做一些初始化操作,可以不必让外部调用 {@link #setData(Object)}, 在 {@link #initData(Bundle)} 中初始化就可以了
     * <p>
     * Example usage:
     * <pre>
     * public void setData(@Nullable Object data) {
     *     if (data != null && data instanceof Message) {
     *         switch (((Message) data).what) {
     *             case 0:
     *                 loadData(((Message) data).arg1);
     *                 break;
     *             case 1:
     *                 refreshUI();
     *                 break;
     *             default:
     *                 //do something
     *                 break;
     *         }
     *     }
     * }
     *
     * // call setData(Object):
     * Message data = new Message();
     * data.what = 0;
     * data.arg1 = 1;
     * fragment.setData(data);
     * </pre>
     *
     * @param data 当不需要参数时 {@code data} 可以为 {@code null}
     */
    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void showLoading() {
        loadingDialog.show();
    }

    @Override
    public void hideLoading() {
        loadingDialog.dismiss();
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.MemberUpdatelevelPaymentFragment_money_txt, R.id.MemberUpdatelevelPaymentFragment_sure_txt})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.MemberUpdatelevelPaymentFragment_money_txt:
                break;
            case R.id.MemberUpdatelevelPaymentFragment_sure_txt:
//                (memberCenterUserInfoBean.getSecondHandReleaseCount() + memberCenterUserInfoBean.getHouseRentReleaseCount()) >= (mmemberLevelBean.getHouseTotal() + mmemberLevelBean.getSecondHandTotal())
                if (mmemberLevelBean.getHouseTotal() != -1 && mmemberLevelBean.getSecondHandTotal() != -1 && memberCenterUserInfoBean.getSecondHandTotal() != -1 && memberCenterUserInfoBean.getHouseTotal() != -1 &&
                        (mmemberLevelBean.getHouseTotal()<memberCenterUserInfoBean.getHouseRentReleaseCount()&&mmemberLevelBean.getSecondHandTotal()<memberCenterUserInfoBean.getSecondHandReleaseCount())) {
                    new AlertView("提示", "你当前累计发布数量已超过" + mmemberLevelBean.getLevelName() + "可发布上限" + (memberCenterUserInfoBean.getMemberLevel().getLevelType() == 2 ? "。" : ("，如需发布更多宝贝\n" +
                            "请开通其他高级会员！")), "我知道了", null, null, getActivity(), AlertView.Style.Alert, new AlertViewOnItemClickListener() {

                        @Override
                        public void onItemClick(Object o, int position) {
                            if (position == AlertView.CANCELPOSITION) {
                                //点击取消按钮

                            } else {

                            }
                        }
                    }).show();
                    return;
                }
                if ((mmemberLevelBean.getHouseTotal()!=-1&&memberCenterUserInfoBean.getHouseRentReleaseCount()>mmemberLevelBean.getHouseTotal())&&(mmemberLevelBean.getSecondHandTotal()!=-1&&memberCenterUserInfoBean.getSecondHandReleaseCount()>mmemberLevelBean.getSecondHandTotal()))
                {
                    new AlertView("提示", "当前会员等级不支持已发布的数量展示", "我知道了", null, null,getActivity(), AlertView.Style.Alert, new AlertViewOnItemClickListener() {

                        @Override
                        public void onItemClick(Object o, int position) {
                            if (position == AlertView.CANCELPOSITION) {
                                //点击取消按钮

                            } else {

                            }
                        }
                    }).show();
                    return;
                }
                mPresenter.getExchangeRate(memberCenterUserInfoBean.getMemberLevel().getLevelType()==0?"":mPresenter.getConfigureId(memberFeatureBeansForNow), memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex).getMemberUpgradeRuleId());
                break;
        }
    }

    @Override
    public void getMemberUpgradeRuleListSuccess(List<MemberCenterUserInfoBean.MemberLevelBean> memberLevelBeans) {
        UpgradeRules.put(MemberUpdatelevelPaymentFragmentZdxfCheckbox.isChecked(), memberLevelBeans);
        MemberUpdatelevelPaymentFragmentMoneyTxt.setText(AppUtil.moneyForat(String.valueOf(memberLevelBeans.get(0).getDiscountAmount())) + "P");
        memberUpdateLevelRuleAdapter.setAutoRenew(MemberUpdatelevelPaymentFragmentZdxfCheckbox.isChecked());
        memberUpdateLevelRuleAdapter.setNewData(memberLevelBeans);
        if (memberLevelBeans == null || memberLevelBeans.isEmpty()) {
            return;
        }
        if (!MemberUpdatelevelPaymentFragmentZdxfCheckbox.isChecked()) {
            MemberUpdatelevelPaymentFragmentZdxfTxt.setText("到期前1天自动续费" + memberLevelBeans.get(selectRuleIndex).getMonthAmount() + "P/月，可随时取消");
        } else {
            MemberUpdatelevelPaymentFragmentZdxfTxt.setText("到期前1天自动续费" + memberLevelBeans.get(selectRuleIndex).getDiscountAmount() + "P，可随时取消");
        }
        //请求到期提示数据
        tsShowContrl_new(memberCenterUserInfoBean, memberLevelBeans.get(0));
    }

    @Override
    public void getMemberFunctionConfigureSuccess(List<MemberFeatureBean> memberFeatureBeans) {
        mmemberFeatureBeans = memberFeatureBeans;
        memberUpdateLevelFeatureAdapter.setNewData(memberFeatureBeans);
    }

    @Override
    public void memberPaySuccess(MemberPayResultBean memberPayResultBean) {
        //支付成功,
        Intent intent = new Intent();
        intent.putExtra("isDialogShow", (mmemberLevelBean.getListOrder() > memberCenterUserInfoBean.getMemberLevel().getListOrder()&&memberCenterUserInfoBean.getStoreCount()==0&&memberCenterUserInfoBean.getStoreTotal()==0));
        AppUtil.isDialogShow = (mmemberLevelBean.getListOrder() > memberCenterUserInfoBean.getMemberLevel().getListOrder()&&memberCenterUserInfoBean.getStoreCount()==0&&memberCenterUserInfoBean.getStoreTotal()==0);
        ((MemberCenterUpdateLevelActivity) getActivity()).setResult(Activity.RESULT_OK, intent);
        ((MemberCenterUpdateLevelActivity) getActivity()).killMyself();
    }

    @Override
    public void getExchangeRateSuccess(String configureId, ExchangeRateBean exchangeRateBean) {

        mPresenter.payPopuWindow(configureId, getActivity(), MemberUpdatelevelPaymentFragmentSureTxt, mhousePayWayBeans, exchangeRateBean, memberUpdateLevelRuleAdapter.getData().get(selectRuleIndex), mmemberLevelBean,memberCenterUserInfoBean);
    }

    @Override
    public void dictListSuccess(List<HousePayWayBean> housePayWayBeans) {
        mhousePayWayBeans = housePayWayBeans;
    }

    @Override
    public void getMemberFunctionConfigureSuccessForNow(List<MemberFeatureBean> memberFeatureBeans) {
        memberFeatureBeansForNow=memberFeatureBeans;
    }

    /**
     * 控制确认按钮的显示状态
     */
    public void setConfireBtn() {
        if (memberCenterUserInfoBean == null || mmemberLevelBean == null) {

            return;
        }
        if (mmemberLevelBean.getListOrder() < memberCenterUserInfoBean.getMemberLevel().getListOrder()) {
            MemberUpdatelevelPaymentFragmentSureTxt.setEnabled(false);
            MemberUpdatelevelPaymentFragmentSureTxt.setTextColor(ArmsUtils.getColor(getActivity(), R.color.white));
            MemberUpdatelevelPaymentFragmentSureTxt.setBackgroundResource(R.drawable.button_gray_bg);
        } else {
            MemberUpdatelevelPaymentFragmentSureTxt.setEnabled(true);
            MemberUpdatelevelPaymentFragmentSureTxt.setTextColor(ArmsUtils.getColor(getActivity(), R.color.color_191919));
            MemberUpdatelevelPaymentFragmentSureTxt.setBackgroundResource(R.drawable.button_yellow_bg);
        }
    }


    //微信支付成功后回调
    @Subscriber(mode = ThreadMode.MAIN)
    public void wxPayFinish(BaseResp baseResp) {
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                mPresenter.wxPaySuccess();
                break;

        }
    }


    /**
     * 控制提示的显示和隐藏
     *
     * @param tememberCenterUserInfoBean
     * @param temmemberLevelBean
     */
    public void tsShowContrl_new(MemberCenterUserInfoBean tememberCenterUserInfoBean, MemberCenterUserInfoBean.MemberLevelBean temmemberLevelBean) {
        if (tememberCenterUserInfoBean == null || temmemberLevelBean == null) {
            MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.GONE);
            return;
        }
        int day = (int) Math.ceil(((tememberCenterUserInfoBean.getResidualAmount() / temmemberLevelBean.getDayAmount())));//从规则列表取每天的钱

        if (day < 1 || tememberCenterUserInfoBean.getMemberLevel().getListOrder() > mmemberLevelBean.getListOrder() || tememberCenterUserInfoBean.getResidualTimeDay() < 1) {
            MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.GONE);
            return;
        }
        MemberUpdatelevelPaymentFragmentTsLay.setVisibility(View.VISIBLE);
        if (tememberCenterUserInfoBean.getMemberLevel().getListOrder() == mmemberLevelBean.getListOrder()) {
            MemberUpdatelevelPaymentFragmentTsTxt.setText("您的" + tememberCenterUserInfoBean.getMemberLevel().getLevelName() + "于" + tememberCenterUserInfoBean.getMemberLevel().getExpiresTime() + "日到期，购买后有效期将顺延");
            return;
        }

        MemberUpdatelevelPaymentFragmentTsTxt.setText("您的" + tememberCenterUserInfoBean.getMemberLevel().getLevelName() + "还有" + tememberCenterUserInfoBean.getResidualTimeDay() + "天到期，如需升级到" + mmemberLevelBean.getLevelName() + "将为您自动兑换成" + day + "天" + mmemberLevelBean.getLevelName() + "，即购买后有效期将顺延" + day + "天。");

    }
}
